home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2579 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: *Pointer to Functions();   /* HELP */
  5. Date: Mon, 22 Jan 96 13:38:45 GMT
  6. Organization: none
  7. Message-ID: <822317925snz@genesis.demon.co.uk>
  8. References: <4dvrq8$c2c@news.unicomp.net>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4dvrq8$c2c@news.unicomp.net> jgore@conline.com "Jerry_Gore" writes:
  15.  
  16. >How do I pass a pointer to a funtion?
  17. >The following is found in a program:
  18. >
  19. >    #define WORD    unsigned int       
  20. >    void    InstallTimer0(WORD period,void far (*func)(void));
  21. >
  22. >My function is thus:
  23. >
  24. >    void far animate(void)    /* I added 'far' for no good reason.   */
  25. >    {                         /* It uses that name in InstallTimer0. */ 
  26.  
  27. Bad news as far as comp.lang.c is concerned - 'far' is not part of the
  28. C language.
  29.  
  30. >    /* do what ever */        
  31. >    return;
  32. >    }
  33. >
  34. >How do I send InstallTimer0 the pointer to my function animate ???
  35. >I tried:
  36. >
  37. >     InstallTimer0(120 , (*animate)());
  38.  
  39. Simply use:
  40.  
  41.       InstallTimer0(120 , animate);
  42.  
  43. A function name (or indeed any expression that designates a function)
  44. evaluates to a pointer to the function in equivalent circumstances where
  45. an array name/expression evaluates to a pointer to the first element
  46. of the array. () as an operator calls the function, if you don't want
  47. to do that you don't use ().
  48.  
  49. -- 
  50. -----------------------------------------
  51. Lawrence Kirby | fred@genesis.demon.co.uk
  52. Wilts, England | 70734.126@compuserve.com
  53. -----------------------------------------
  54.